/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */


package com.android1.amarena2d.nodes.behavior.delegates;

import com.android1.amarena2d.commons.Tools;
import com.android1.amarena2d.engine.GL;
import com.android1.amarena2d.nodes.Entity;

public class GLTransformDelegate extends DefaultTransformDelegate implements TransformDelegate {


    public GLTransformDelegate(Entity entity) {
        super(entity);
    }


    public void applyGL() {

        if (rotation != 0.0F || scaleX != 1.0F || scaleY != 1.0F) {

            final boolean hasTransformanchor = !(transformAnchorPos == null || Tools.isZero(transformAnchorPos));

            if (hasTransformanchor)
                GL.translate(transformAnchorPos.x, transformAnchorPos.y);


            if (scaleX != 1.0F || scaleY != 1.0F)
                GL.scale(scaleX, scaleY);

            if (rotation != 0.0F)
                GL.rotate(rotation);

            if (hasTransformanchor)
                GL.translate(-(transformAnchorPos.x), -(transformAnchorPos.y));

//                //absolute position transform
//                if (hasTransformanchor)
//                    GL.translate(transformAnchorPos.x - origion.x, transformAnchorPos.y - origion.y);
//
//                if (rotation != 0.0F)
//                    GL.rotate(rotation);
//
//                if (scaleX != 1.0F || scaleY != 1.0F)
//                    GL.scale(scaleX, scaleY);
//
//                if (hasTransformanchor)
//                    GL.translate(-(transformAnchorPos.x - origion.x), -(transformAnchorPos.y - origion.y));
        }
    }
}
